import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Hi from '@/components/Hi'
import Hi1 from '@/components/Hi-1'
import Hi2 from '@/components/Hi-2'
import Hi21 from '@/components/Hi-2-1'
import Error from '@/components/Error'
import Params from '@/components/Params'
import Count from '@/components/Count'
import Hello from '@/components/Hello'


Vue.use(Router) //vue 加载router模块

export default new Router({
    routes: [{
            path: '/',
            name: 'HelloWorld',
            //component: HelloWorld,
            // beforeEnter: (to, from, next) => {
            //     console.log('进入了 helloword 组件模板');
            //     console.log(to);
            //     console.log(from);
            // }
            components: { //路由后 解析多组件（模板）
                default: HelloWorld,
                left: Hi1,
                right: Hi2
            }
        }, {
            path: '/hi', // router-link 的 to 用到
            name: 'Hi', //router-link 传参时， 属性 to 用到
            component: Hi, //路由后 解析的模板
            children: [
                { path: 'hi1', name: 'Hi1', component: Hi1 },
                { path: 'hi2', name: 'Hi2', component: Hi2, children: [{ path: 'hi21', name: "hi21", component: Hi21 }] }
            ]
        }, {
            path: '/params/:newsId(\\d+)/:newsTitle', //占位符，用正则时，需以圆括号的形式加入
            name: 'params',
            component: Params //路由后 解析的模板

        }, {
            path: '/gohome',
            redirect: '/' //用redirect 来代替component 
        }, {
            path: '/gotoparams/:newsId(\\d+)/:newsTitle',
            redirect: '/params/:newsId(\\d+)/:newsTitle' //redirect 时带参数。
        }, {
            path: '/count',
            name: 'store',
            component: Count
        }, {
            path: '/hello',
            name: 'hello',
            component: Hello
        },





        {
            path: '*', //所有路由不匹配时，会匹配这
            component: Error,
        }
    ]
})